package cn.edu.scau.cmi.prewarning.domain;


import java.io.Serializable;

import java.lang.StringBuilder;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.persistence.*;
import javax.xml.bind.annotation.*;
import java.util.Set;
import com.alibaba.fastjson.annotation.JSONField;

@Entity
@NamedQueries({ @NamedQuery(name = "findAllEvents", query = "select myEvent from Event myEvent"),
		@NamedQuery(name = "findEventByName", query = "select myEvent from Event myEvent where myEvent.name = ?1"),
		@NamedQuery(name = "findEventByNameContaining", query = "select myEvent from Event myEvent where myEvent.name like concat('%',?1,'%')"),
		@NamedQuery(name = "findEventByDescription", query = "select myEvent from Event myEvent where myEvent.description = ?1"),
		@NamedQuery(name = "findEventByDescriptionContaining", query = "select myEvent from Event myEvent where myEvent.description like concat('%',?1,'%')"),
		@NamedQuery(name = "findAllEventsByDiscoveryaddress", query = "select myEvent from Event myEvent where myEvent.discoveryaddress.id = ?1"),
		@NamedQuery(name = "findAllEventsBySourceaddress", query = "select myEvent from Event myEvent where myEvent.sourceaddress.id = ?1"),
		@NamedQuery(name = "findAllEventsByFood", query = "select myEvent from Event myEvent where myEvent.food.id = ?1"),
		@NamedQuery(name = "findAllEventsByFoodtype", query = "select myEvent from Event myEvent where myEvent.foodtype.id = ?1"),
		@NamedQuery(name = "findAllEventsByFiller", query = "select myEvent from Event myEvent where myEvent.filler.id = ?1"),
		@NamedQuery(name = "findEventById", query = "select myEvent from Event myEvent where myEvent.id = ?1"),
		@NamedQuery(name = "findEventByPrimaryKey", query = "select myEvent from Event myEvent where myEvent.id = ?1 "),
		@NamedQuery(name = "deleteEventsByIds", query = "delete Event where id in (?1)"),
		@NamedQuery(name = "findEventsByIds", query = "select myEvent from Event myEvent where myEvent.id in (?1)"),
		@NamedQuery(name = "findEventByPhyscialPrimaryKey", query = "select myEvent from Event myEvent where  myEvent.id = ?1"),
		@NamedQuery(name = "countEventsByName", query = "select count(myEvent)  from Event myEvent where myEvent.name like concat('%',?1,'%')") })
@Table(catalog = "emaprewarning", name = "event")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "emaprewarning/cn/edu/scau/cmi/emaprewarning/domain", name = "Event")
@XmlRootElement(namespace = "emaprewarning/cn/edu/scau/cmi/emaprewarning/domain")

public class Echartevent implements Serializable, Comparable<Echartevent> {

	private static final long serialVersionUID = 1L;

	@Column(name = "id", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@XmlElement
	Integer id;

	@Column(name = "name")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String name;

	@Column(name = "description")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String description;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "discoveryaddress", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Address discoveryaddress;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "sourceaddress", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Address sourceaddress;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "food", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Food food;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "foodtype", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Foodtype foodtype;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "filler", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Filler filler;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return this.id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDiscoveryaddress(Address discoveryaddress) {
		this.discoveryaddress = discoveryaddress;
	}

	public Address getDiscoveryaddress() {
		return discoveryaddress;
	}

	public void setSourceaddress(Address sourceaddress) {
		this.sourceaddress = sourceaddress;
	}

	public Address getSourceaddress() {
		return sourceaddress;
	}

	public void setFood(Food food) {
		this.food = food;
	}

	public Food getFood() {
		return food;
	}

	public void setFoodtype(Foodtype foodtype) {
		this.foodtype = foodtype;
	}

	public Foodtype getFoodtype() {
		return foodtype;
	}

	public void setFiller(Filler filler) {
		this.filler = filler;
	}

	public Filler getFiller() {
		return filler;
	}

	public void copy(Echartevent that) {

		setId(that.getId());

		setName(that.getName());
		setDescription(that.getDescription());

		setDiscoveryaddress(that.getDiscoveryaddress());

		setSourceaddress(that.getSourceaddress());

		setFood(that.getFood());

		setFoodtype(that.getFoodtype());

		setFiller(that.getFiller());

	}

	public Echartevent() {

	}

	@Override
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");

		buffer.append("name=[").append(name).append("] ");
		buffer.append("description=[").append(description).append("] ");

		return buffer.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Echartevent))
			return false;
		Echartevent comparedEvent = (Echartevent) obj;
		if (!CheckPropertyEqual(this.id, comparedEvent.id)) {
			return false;
		}
		return true;
	}

	public static <T> boolean CheckPropertyEqual(T originProperty, T comparedProperty) {
		// 基本类型经过参数传递后会自动装箱
		String[] className = originProperty.getClass().getName().split("\\.");
		if (className[0].equals("java") && className[1].equals("math")) {
			return ((Comparable) originProperty).compareTo(comparedProperty) == 0 ? true : false;
		} else {
			return originProperty.equals(comparedProperty);
		}
	}

	@Override
	public int compareTo(Echartevent o) {
		if (this.getId() > o.getId()) {
			return 1;
		} else if (this.getId() == o.getId()) {
			return 0;
		} else {
			return -1;
		}

	}
}
